package previous.Test_0403;

import java.util.*;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Bridge_Blue {
    //移动距离(该题还有另一种解法)
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int w=scan.nextInt();
        int m=scan.nextInt();
        int n=scan.nextInt();
        int x=Math.max(m, n)/w+1;
        Queue<int[]> queue=new LinkedList<int[]>();
        boolean[][] check=new boolean[x+1][w+1];
        int[][] a=new int[x+1][w+1];
        for(int i=1;i<=x;i++) {
            if(i%2==1) {
                for(int j=1;j<=w;j++) {
                    a[i][j]=(i-1)*w+j;
                    if(a[i][j]==m) {
                        queue.add(new int[] {i,j});
                        check[i][j]=true;
                    }
                }
            }else {
                for(int j=1;j<=w;j++) {
                    a[i][j]=i*w-j+1;
                    if(a[i][j]==m) {
                        queue.add(new int[] {i,j});
                        check[i][j]=true;
                    }
                }
            }

        }

        int[] dx= {0,0,1,-1};
        int[] dy= {1,-1,0,0};
        int step=0;
        while(!queue.isEmpty()) {
            int size=queue.size();
            for(int j=0;j<size;j++) {
                int[] t=queue.poll();
                int z=t[0];
                int b=t[1];
                if(a[z][b]==n) {
                    System.out.println(step);
                    return;
                }
                for(int i=0;i<4;i++) {
                    int x1=dx[i]+z;
                    int y1=dy[i]+b;
                    if(x1>=1 && x1<=x && y1>=1 && y1<=w && check[x1][y1]!=true) {
                        queue.add(new int[]{x1,y1});
                        check[x1][y1]=true;
                    }
                }
            }
            step++;
        }
        scan.close();
    }
}
